/**
 * 作者: hxl
 * 日期: 2025-03-10 17:29:35
 * 备注: 用户限时冲榜信息表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.commondata.act.ActRechargeTask;
import com.motu.monstercity.server.game.commondata.act.ActRechargeTaskType;
import com.motu.monstercity.server.game.logic.RankActManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;
import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

public class UserRankAct extends UserRankActModel {
    public UserRankAct() {
        super();
    }

    public UserRankAct(long userId, long round, long rankId) {
        putUserId(userId);
        putRound(round);
        putActId(rankId);
    }

    public void reset() {
        if (!TimeUtils.isToday(resetTime)) {
            putRechargeDayBuy("");
            resetRechargeTask();
            putResetTime(TimeUtils.getCurTime());
            update();
        }
    }

    public void resetRechargeTask() {
        JsonArray taskGetArray = getRechargeTaskGetArray();
        JsonArray newTaskGetArray = new JsonArray();
        for (int i = 0; i < taskGetArray.size(); i++) {
            int taskId = taskGetArray.getInteger(i);
            ActRechargeTask actTask = RankActManager.getActRechargeTask(taskId);
            if (actTask != null) {
                ActRechargeTaskType actTaskType = RankActManager.getActRechargeTaskType(actTask.getTaskType());
                if (actTaskType != null && actTaskType.getType() != ActRechargeTaskType.RESET_TYPE_DAILY) {
                    newTaskGetArray.add(taskId);
                }
            }
        }
        putRechargeTaskGet(newTaskGetArray.toString());
    }

    public void checkReset(long round) {
        if (getRound() != round) {
            putRankGet("");
            putTaskGet("");
            putRechargeDayBuy("");
            putRechargeBuy("");
            putRound(round);
            update();
        }
    }

    /**
     * 是否需要补发奖励
     * @return 如果补发轮次等于当前轮次，则返回false
     */
    public boolean needReissue() {
        return round != reissueRound;
    }

    public JsonObject getRechargeBuyJson() {
        return Tool.isEmpty(rechargeBuy) ? new JsonObject() : new JsonObject(rechargeBuy);
    }

    public JsonObject getRechargeDayBuyJson() {
        return Tool.isEmpty(rechargeDayBuy) ? new JsonObject() : new JsonObject(rechargeDayBuy);
    }

}
